package UserAdapter;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.talksdk.R;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import UserGlobal.GlobalData;

public class ChatAdapter extends RecyclerView.Adapter<ChatAdapter.ViewHolder> {
    class ViewHolder extends RecyclerView.ViewHolder {
        TextView textView;
        LinearLayout linearLayout;
        public ViewHolder(View itemView) {
            super(itemView);
            textView=itemView.findViewById(R.id.chatitemtextview);
            linearLayout=itemView.findViewById(R.id.chatitemlinear);
        }
    }
    public ChatAdapter(){

    }
    public void addGravityList(Integer a, String b){
        Map<Integer,String> map=new HashMap<>();
        map.put(a,b);
        GlobalData.mGravityList.add(map);
    }
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.chatitem,parent,false);
        ViewHolder viewHolder=new ViewHolder(view);
        return viewHolder;
    }
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Iterator mIterator=GlobalData.mGravityList.get(position).keySet().iterator();
        Integer integer= (Integer) mIterator.next();
        holder.linearLayout.setGravity(integer);
        holder.textView.setText(GlobalData.mGravityList.get(position).get(integer));
    }
    @Override
    public int getItemCount() {
        return GlobalData.mGravityList.size();
    }
}
